package com.company.huisuo.repository

import com.company.huisuo.biz.bean.ServiceStyleBean
import com.company.huisuo.biz.bean.ServiceStyleListResponse
import com.company.huisuo.network.RetrofitClient
import com.company.huisuo.network.api.ServiceStyleApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 服务风格数据仓库
 */
class ServiceStyleRepository {
    
    private val serviceStyleApi: ServiceStyleApi by lazy {
        RetrofitClient.createService()
    }
    
    /**
     * 获取服务风格列表
     */
    suspend fun getServiceStyles(): Result<List<ServiceStyleBean>> = withContext(Dispatchers.IO) {
        try {
            val response = serviceStyleApi.getRoomStyleList()
            if (response.code == 200 && response.data != null) {
                Result.success(response.data)
            } else {
                Result.failure(Exception(response.message ?: "获取服务风格列表失败"))
            }
        } catch (e: Exception) {
            Result.failure(Exception("网络请求失败: ${e.message}"))
        }
    }
    
    /**
     * 获取服务风格列表（转换为Pair格式）
     */
    suspend fun getServiceStylePairs(): Result<List<Pair<Int, String>>> = withContext(Dispatchers.IO) {
        try {
            val response = serviceStyleApi.getRoomStyleList()
            if (response.code == 200 && response.data != null) {
                val pairs = response.data.map { ServiceStyleBean.toPair(it) }
                Result.success(pairs)
            } else {
                Result.failure(Exception(response.message ?: "获取服务风格列表失败"))
            }
        } catch (e: Exception) {
            Result.failure(Exception("网络请求失败: ${e.message}"))
        }
    }
}